define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'classroom/banner/index' + location.search,
                    add_url: 'classroom/banner/add',
                    edit_url: 'classroom/banner/edit',
                    del_url: 'classroom/banner/del',
                    multi_url: 'classroom/banner/multi',
                    import_url: 'classroom/banner/import',
                    table: 'classroom_banner',
                }
            });

            var table = $("#table");

            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone,.btn-edit,.btn-add").data("area", ["95%", "95%"]);
                $(".btn-editone,.btn-edit,.btn-add").data("shade", 0.5);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'type', title: __('Type'), searchList: { "0": __('学习'), "1": __('活动'), "2": __('首页'), "3": __('党会'), "5": __('我的') }, formatter: Table.api.formatter.normal },
                        { field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'url', title: __('Url'), operate: 'LIKE', formatter: Table.api.formatter.url },
                        { field: 'weigh', title: __('Weigh'), operate: false },
                        { field: 'status', title: __('状态'), table: table, formatter: Table.api.formatter.toggle, yes: 'normal', no: 'hidden' },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                // 选择页面
                $(document).on("click", ".btn-select-page", function (e, obj) {
                    var that = this;
                    Fast.api.open("classroom/pages/get_page_list", "选择路径", {
                        callback: function (data) {
                            $(that).parent().prev().val(data);
                        }
                    });
                });
            }
        }
    };
    return Controller;
});